package classical_problems_150;

public class P_0125 {

    public boolean isPalindrome(String s) {
        String str = s.toUpperCase();
        int i=0;
        int j=str.length()-1;
        while(i<j){
            while( !(str.charAt(i) <= 'Z' && str.charAt(i) >= 'A' || str.charAt(i) <= '9' && str.charAt(i) >= '0') && i<j) i++;
            while( !(str.charAt(j) <= 'Z' && str.charAt(j) >= 'A' || str.charAt(j) <= '9' && str.charAt(j) >= '0') && i<j) j--;
            if(str.charAt(i)!=str.charAt(j)) break;
            else {
                i++;
                j--;
            }
        }

        return i>=j;
    }

    public static void main(String[] args){
        P_0125 solution = new P_0125();
        String str = "A man, a plan, a canal: Panama";
        boolean b = solution.isPalindrome(str);
    }
}
